﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Media;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Graph = Microsoft.Office.Interop.Graph;
using System.Runtime.InteropServices;
namespace DataLayer
{
    public class RootNode : Node
    {
        public override void RemoveNode(string _name)
        {
            if(this.Name != _name)
                base.RemoveNode(_name);
        }

        public void AddToXmlDoc(XmlDocument _doc)
        {
            XmlElement mapnode = _doc.CreateElement("map");
            _doc.RemoveAll();
            _doc.AppendChild(mapnode);

            XmlElement root = _doc.CreateElement("rootnode");
            XmlAttribute nameAtt = _doc.CreateAttribute("name");
            nameAtt.Value = this.Name;
            XmlAttribute color = _doc.CreateAttribute("color");
            color.Value = this.Color.ToString();
            XmlAttribute xAtt = _doc.CreateAttribute("x");
            xAtt.Value = this.X.ToString();
            XmlAttribute yAtt = _doc.CreateAttribute("y");
            yAtt.Value = this.y.ToString();
            XmlAttribute dirAtt = _doc.CreateAttribute("direction");
            dirAtt.Value = this.Direction.ToString();
            XmlAttribute expandAtt = _doc.CreateAttribute("expand");
            expandAtt.Value = this.IsExpanded.ToString();

            root.Attributes.Append(nameAtt);
            root.Attributes.Append(color);
            root.Attributes.Append(xAtt);
            root.Attributes.Append(yAtt);
            root.Attributes.Append(dirAtt);
            root.Attributes.Append(expandAtt);


            mapnode.AppendChild(root);
            AddToXmlDoc(_doc, root);
        }

        public override void CheckLevel()
        {
            ErrorType errorType = ErrorTypesHelper.GetInstance().GetErrorTypeByName("LevelError");
            int nodeLevel = this.ComputeLevel();
            if (nodeLevel >= errorType.Boundary)
            {
                if (this.ErrorList == null)
                    this.ErrorList = new List<int>();
                this.AddError(errorType.Id);
            }
        }

        public override void AddNodeToSlide(PowerPoint.Slides objSlides, ref int indexslide)
        {
            PowerPoint.Slide objSlide = objSlides.Add(indexslide, PowerPoint.PpSlideLayout.ppLayoutTitle);

            PowerPoint.TextRange objTextRng = objSlide.Shapes[1].TextFrame.TextRange;

            objTextRng.Text = this.Name;

            objTextRng.Font.Name = "Comic Sans MS";

            objTextRng.Font.Size = 48;
            indexslide++;
            base.AddNodeToSlide(objSlides, ref indexslide);
        }
    }
}
